/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package radiostation;

import java.awt.Component;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import model.Artist;
import model.DBManager;
import model.MusicGroup;

/**
 *
 * @author david
 */
public class EditGroupFrame extends javax.swing.JFrame {

    /**
     * Creates new form EditGroupFrame
     */
    public EditGroupFrame() {
        
        em = DBManager.em;
        if(!em.getTransaction().isActive())
        {
            em.getTransaction().begin();
        }
        initComponents();
    }
    
    public EditGroupFrame(MusicGroup musicgroup) {
        
        em = DBManager.em;
        this.musicgroup = musicgroup;
        if(!em.getTransaction().isActive())
        {
            em.getTransaction().begin();
        }
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        musicGroup1 = this.musicgroup;
        radiostationPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("radiostationPU").createEntityManager();
        artistQuery = java.beans.Beans.isDesignTime() ? null : radiostationPUEntityManager.createQuery("SELECT a FROM Artist a WHERE a.artistMusicGroupId=:musicGroupId").setParameter("musicGroupId", musicGroup1);
        artistList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(artistQuery.getResultList());
        artistQuery1 = java.beans.Beans.isDesignTime() ? null : em.createQuery("SELECT a FROM Artist a");
        artistList1 = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(artistQuery1.getResultList());
        headerPanel = new javax.swing.JPanel();
        headerLabel = new javax.swing.JLabel();
        groupNameLabel = new javax.swing.JLabel();
        groupNameTextField = new javax.swing.JTextField();
        groupFormDateLabel = new javax.swing.JLabel();
        groupFormDateTextField = new javax.swing.JTextField();
        groupArtistListPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        groupArtistListTable = new javax.swing.JTable();
        dataArtistPanel = new javax.swing.JPanel();
        insertGroupArtistBtn = new javax.swing.JButton();
        deleteGroupArtistBtn = new javax.swing.JButton();
        artistListComboBox = new javax.swing.JComboBox();
        actionPanel = new javax.swing.JPanel();
        cancelButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Διαχείριση Συγκροτήματος");

        headerPanel.setBackground(new java.awt.Color(255, 204, 0));
        headerPanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        headerLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        headerLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        headerLabel.setText("Διαχείριση Συγκροτήματος");
        headerLabel.setToolTipText("");

        javax.swing.GroupLayout headerPanelLayout = new javax.swing.GroupLayout(headerPanel);
        headerPanel.setLayout(headerPanelLayout);
        headerPanelLayout.setHorizontalGroup(
            headerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(headerPanelLayout.createSequentialGroup()
                .addGap(296, 296, 296)
                .addComponent(headerLabel)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        headerPanelLayout.setVerticalGroup(
            headerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(headerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(headerLabel)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        groupNameLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        groupNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        groupNameLabel.setText("Επωνυμία Συγκροτήματος :");

        groupNameTextField.setToolTipText("");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, musicGroup1, org.jdesktop.beansbinding.ELProperty.create("${musicGroupName}"), groupNameTextField, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        groupFormDateLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        groupFormDateLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        groupFormDateLabel.setText("Ημερομηνία Δημιουργίας :");
        groupFormDateLabel.setToolTipText("");

        groupFormDateTextField.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        groupFormDateTextField.setToolTipText("");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, musicGroup1, org.jdesktop.beansbinding.ELProperty.create("${musicGroupFormdate}"), groupFormDateTextField, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        groupArtistListPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Λίστα Καλλιτεχνών"));

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, artistList, groupArtistListTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${artistFname}"));
        columnBinding.setColumnName("Όνομα");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${artistLname}"));
        columnBinding.setColumnName("Επώνυμο");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${artistArtname}"));
        columnBinding.setColumnName("Καλλιτεχνικό Όνομα");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${artistSex}"));
        columnBinding.setColumnName("Φύλο");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${artistBirthDay}"));
        columnBinding.setColumnName("Ημερομηνία Γέννησης");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${artistBirthPlace}"));
        columnBinding.setColumnName("Τόπος Γέννησης");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane1.setViewportView(groupArtistListTable);

        javax.swing.GroupLayout groupArtistListPanelLayout = new javax.swing.GroupLayout(groupArtistListPanel);
        groupArtistListPanel.setLayout(groupArtistListPanelLayout);
        groupArtistListPanelLayout.setHorizontalGroup(
            groupArtistListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(groupArtistListPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
        );
        groupArtistListPanelLayout.setVerticalGroup(
            groupArtistListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(groupArtistListPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        dataArtistPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Εισαγωγή - Διαγραφή Καλλιτέχνη"));

        insertGroupArtistBtn.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        insertGroupArtistBtn.setText("Εισαγωγή");
        insertGroupArtistBtn.setToolTipText("");
        insertGroupArtistBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insertGroupArtistBtnActionPerformed(evt);
            }
        });

        deleteGroupArtistBtn.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        deleteGroupArtistBtn.setText("Διαγραφή");
        deleteGroupArtistBtn.setToolTipText("");
        deleteGroupArtistBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteGroupArtistBtnActionPerformed(evt);
            }
        });

        artistListComboBox.setVisible(false);
        artistListComboBox.setEnabled(false);
        artistListComboBox.setRenderer(new DefaultListCellRenderer(){
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus){
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                if (value instanceof Artist){
                    Artist art = (Artist)value;
                    setText(art.getArtistFname()+" "+art.getArtistLname()+" "+art.getArtistArtname());
                }
                return this;
            }

        });

        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, artistList1, artistListComboBox);
        bindingGroup.addBinding(jComboBoxBinding);

        javax.swing.GroupLayout dataArtistPanelLayout = new javax.swing.GroupLayout(dataArtistPanel);
        dataArtistPanel.setLayout(dataArtistPanelLayout);
        dataArtistPanelLayout.setHorizontalGroup(
            dataArtistPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dataArtistPanelLayout.createSequentialGroup()
                .addGroup(dataArtistPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(dataArtistPanelLayout.createSequentialGroup()
                        .addComponent(insertGroupArtistBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 104, Short.MAX_VALUE)
                        .addComponent(deleteGroupArtistBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(artistListComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        dataArtistPanelLayout.setVerticalGroup(
            dataArtistPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dataArtistPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(dataArtistPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(insertGroupArtistBtn)
                    .addComponent(deleteGroupArtistBtn))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(artistListComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(68, Short.MAX_VALUE))
        );

        actionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Επιλογή Ενέργειας"));

        cancelButton.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        cancelButton.setText("Ακύρωση");
        cancelButton.setToolTipText("");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        saveButton.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        saveButton.setText("Αποθήκευση");
        saveButton.setToolTipText("");
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout actionPanelLayout = new javax.swing.GroupLayout(actionPanel);
        actionPanel.setLayout(actionPanelLayout);
        actionPanelLayout.setHorizontalGroup(
            actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(actionPanelLayout.createSequentialGroup()
                .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35)
                .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        actionPanelLayout.setVerticalGroup(
            actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(actionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelButton)
                    .addComponent(saveButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(groupArtistListPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(headerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(groupNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(groupNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(118, 118, 118)
                        .addComponent(groupFormDateLabel)
                        .addGap(18, 18, 18)
                        .addComponent(groupFormDateTextField))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(dataArtistPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 114, Short.MAX_VALUE)
                        .addComponent(actionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(19, 19, 19)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(headerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(groupNameLabel)
                    .addComponent(groupNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(groupFormDateLabel)
                    .addComponent(groupFormDateTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(groupArtistListPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(dataArtistPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(actionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void closeMe(boolean exitAndSave)
    {
        MyWindowEvent we = new MyWindowEvent(this, WindowEvent.WINDOW_CLOSED, exitAndSave);
        for (WindowListener l : this.getWindowListeners())
        {
            l.windowClosed(we);
            
        }
        this.setVisible(false);
    }
    
    ItemListener itemListener = new ItemListener() {
      public void itemStateChanged(ItemEvent itemEvent) 
      {
          artist = (Artist)artistListComboBox.getSelectedItem();
          int state = itemEvent.getStateChange();
         
          if(state==ItemEvent.SELECTED)
          {
              for (Artist art : artistList)
              {
                  if (art.equals(artist))
                  {
                      JOptionPane.showMessageDialog(new JFrame(), "Ο επιλεγμένος καλλιτέχνης είναι ήδη στη λίστα καλλιτεχνών του συγκροτήματος.");
                      return;
                  }
              }
              try
              {
                  if(artist.getArtistMusicGroupId()==null)
                  {
                      int reply = JOptionPane.showConfirmDialog(null, "Επιθυμείτε την εισαγωγή του επιλεγμένου καλλιτέχνη στο συγκρότημα;", "Alert", JOptionPane.YES_NO_OPTION);
                      if (reply == JOptionPane.YES_OPTION)
                      {
                          if (artist instanceof Artist)
                          {
                              artist.setArtistMusicGroupId(musicgroup);
                              artistList.add(artist);
                              return;
                          }
                      }
                  }
              }
              catch(Exception e)
              {
                  
              }
              try
              {
                  if(artist.getArtistMusicGroupId()!=null)
                  {
                      JOptionPane.showMessageDialog(new JFrame(), "Ο επιλεγμένος καλλιτέχνης ανήκει σε άλλο συγκρότημα.");
                      
                  }
              }
              catch(Exception e)
              {
                  
              }
          }
    }
   };

    
    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        // TODO add your handling code here:
        int numberOfArtists=artistList.size();
        int numberOfArtistsForDel = artistsForDel.size();
               
        if(numberOfArtists>=2)
        {
            if(numberOfArtistsForDel>0)
            {
                try
                {
                    for(Artist art:artistsForDel)
                    {
                        art.setArtistMusicGroupId(null);
                        em.merge(art);
                        em.getTransaction().commit();
                        em.getTransaction().begin();
                    }
                }
                catch(Exception e)
                {
                    JOptionPane.showMessageDialog(new JFrame(), "ΣΦΑΛΜΑ - Δεν είναι δυνατόν να διαγραφούν καλλιτέχνες από τη λίστα καλλιτεχνών του συγκροτήματος.");
                    return;
                }
            }
            closeMe(true);
        }
        else
        {
            JOptionPane.showMessageDialog(new JFrame(), "Πρέπει να καταχωρηθούν τουλάχιστον δύο καλλιτέχνες στη λίστα καλλιτεχνών του συγκροτήματος");
        }
        
        
                        
    }//GEN-LAST:event_saveButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        // TODO add your handling code here:
        closeMe(false);
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void insertGroupArtistBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_insertGroupArtistBtnActionPerformed
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(null, "Επιλέξτε έναν καλλιτέχνη για εισαγωγή στο συγκρότημα από την αναδιπλούμενη λίστα.");
        
  
       artistListComboBox.setVisible(true);
       artistListComboBox.setEnabled(true); 
       artistListComboBox.addItemListener(itemListener);

    }//GEN-LAST:event_insertGroupArtistBtnActionPerformed

    private void deleteGroupArtistBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteGroupArtistBtnActionPerformed
        // TODO add your handling code here:
        selecItemNum = groupArtistListTable.getSelectedRow();
        if(selecItemNum>=0)
        {
            artistForDel = artistList.get(groupArtistListTable.convertRowIndexToModel(selecItemNum));
            artistsForDel.add(artistForDel);
            artistList.remove(artistForDel);
        }
        else
        {
            JOptionPane.showMessageDialog(new JFrame(), "Επέλεξε έναν καλλιτέχνη από τον πίνακα.");
        }
    }//GEN-LAST:event_deleteGroupArtistBtnActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(EditGroupFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(EditGroupFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(EditGroupFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(EditGroupFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new EditGroupFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel actionPanel;
    private java.util.List<model.Artist> artistList;
    private java.util.List<model.Artist> artistList1;
    private javax.swing.JComboBox artistListComboBox;
    private javax.persistence.Query artistQuery;
    private javax.persistence.Query artistQuery1;
    private javax.swing.JButton cancelButton;
    private javax.swing.JPanel dataArtistPanel;
    private javax.swing.JButton deleteGroupArtistBtn;
    private javax.swing.JPanel groupArtistListPanel;
    private javax.swing.JTable groupArtistListTable;
    private javax.swing.JLabel groupFormDateLabel;
    private javax.swing.JTextField groupFormDateTextField;
    private javax.swing.JLabel groupNameLabel;
    private javax.swing.JTextField groupNameTextField;
    private javax.swing.JLabel headerLabel;
    private javax.swing.JPanel headerPanel;
    private javax.swing.JButton insertGroupArtistBtn;
    private javax.swing.JScrollPane jScrollPane1;
    private model.MusicGroup musicGroup1;
    private javax.persistence.EntityManager radiostationPUEntityManager;
    private javax.swing.JButton saveButton;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    EntityManager em;
    private MusicGroup musicgroup;
    private Artist artist;
    private Artist artistForDel;
    private int selecItemNum;
    private List<Artist> artistsForDel = new ArrayList<Artist>();
}
